@extends('admin.layout.index')

@section('content')

    <div class="mws-panel-body no-padding">
        <form class="mws-form" action="/admin/good/{{$data['gid']}}" method="post" enctype="multipart/form-data">
            {{csrf_field()}}
            <input type="hidden" name="_method" value="put">
            <div class="mws-form-inline">
                <div class="mws-form-row">
                    <label class="mws-form-label">商品名称</label>
                    <div class="mws-form-item">
                        <input type="text" class="small" name="gname" value="{{$data['gname']}}">
                    </div>
                </div>
                <div class="mws-form-row">
                    <label class="mws-form-label">所属分类</label>
                    <div class="mws-form-item" style="width:300px">
                        <select class="large" name="g_cid">
                            <option>--请选择--</option>
                            @foreach($s as $k=>$v)
                                <option value="{{$v['cid']}}"{{$data['g_cid']==$v['cid']? 'selected':''}}>{{$v['cname']}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="mws-form-row">
                    <label class="mws-form-label">商品特点</label>
                    <div class="mws-form-item">
                        <input type="text" class="small" name="gfeature" value="{{$data['gfeature']}}">
                    </div>
                </div>
                <div class="mws-form-row">
                    <label class="mws-form-label">商品售价</label>
                    <div class="mws-form-item">
                        <input type="text" class="small" name="gcost" value="{{$data['gcost']}}">
                    </div>
                </div>
                <div class="mws-form-row">
                    <label class="mws-form-label">商品库存</label>
                    <div class="mws-form-item">
                        <input type="text" class="small" name="gnum" value="{{$data['gnum']}}">
                    </div>
                </div>
                <div class="mws-form-row">
                    <label class="mws-form-label" >商品图片</label>
                    <div class="mws-form-item"style="width:300px" >
                        {{--<input type="file" class="small" name="gphoto">--}}
                        <input id="gphoto" name="gphoto" type="file" multiple="true" class="small">
                    </div>
                    {{--<p><img id="img1" alt="上传后显示图片"  style="max-width:350px;max-height:100px;" /></p>--}}
                </div>

                <div class="mws-form-row">
                    <label class="mws-form-label">上传后显示图片</label>
                    <div class="mws-form-item">
                        <p><img id="img1" alt="上传后显示图片"  style="max-width:350px;max-height:100px;" /></p>
                    </div>
                </div>

                <div class="mws-form-row">
                    <label class="mws-form-label">商品描述</label>
                    <div class="mws-form-item">


                        <tr>
                            <th>内容：</th>
                            <td>
                                <script type="text/javascript" charset="utf-8" src="{{asset('ueditor/ueditor.config.js')}}"></script>
                                <script type="text/javascript" charset="utf-8" src="{{asset('ueditor/ueditor.all.min.js')}}"> </script>
                                <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
                                <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
                                <script type="text/javascript" charset="utf-8" src="{{asset('ueditor/lang/zh-cn/zh-cn.js')}}"></script>



                                <script id="editor" type="text/plain" name="gcontent" style="width:600px;height:320px;">{!!$data['gcontent']!!}</script>

                                <script>
                                    var ue = UE.getEditor('editor');
                                </script>
                                <style>
                                    .edui-default{line-height: 28px;}
                                    div.edui-combox-body,div.edui-button-body,div.edui-splitbutton-body
                                    {overflow: hidden; height:20px;}
                                    div.edui-box{overflow: hidden; height:22px;}
                                </style>

                            </td>
                        </tr>
                    </div>
                </div>

            </div>
            <div class="mws-button-row">
                <input type="submit" value="Submit" class="btn btn-danger">
                <input type="reset" value="Reset" class="btn ">
            </div>
        </form>
    </div>
    <script type="text/javascript">
        $(function () {

            $("#gphoto").change(function () {
                //alert(1);
                uploadImage();
            });
        });
        //        $(".fileinput-btn btn").click(uploadImage());
        function uploadImage() {
//                            判断是否有选择上传文件
            var imgPath = $("#gphoto").val();
            if (imgPath == "") {
                alert("请选择上传图片！");
                return;
            }
            //判断上传文件的后缀名
            var strExtension = imgPath.substr(imgPath.lastIndexOf('.') + 1);
            if (strExtension != 'jpg' && strExtension != 'gif'
                && strExtension != 'png' && strExtension != 'bmp') {
                alert("请选择图片文件");
                return;
            }
//                            var myform = document.getElementById('art_from');
//            var formData = new FormData($('#art_form')[0]);
                    {{--formData.append('_token', '{{csrf_token()}}');--}}
                    {{--console.log(formData);--}}

            var formData = new FormData();
            formData.append("gphoto", $('#gphoto')[0].files[0]);
            formData.append("_token", '{{csrf_token()}}');
            $.ajax({
                type: "POST",
                url: "/admin/upload",
                data: formData,
                async: true,
                cache: false,
                contentType: false,
                processData: false,
                success: function(data) {
//                                    console.log(data);
//                                    alert("上传成功");
                    $('#img1').attr('src','/'+data);
                    $('#art_thumb').val(data);

                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("上传失败，请检查网络后重试");
                }
            });
        }

    </script>

@endsection